﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SafeScript.MetaModel.Statements
{
    public enum IncDecOperatorKind
    {
        PreInc,
        PreDec,
        PostInc,
        PostDec
    }

    public class IncDecOperator : Operator
    {
        public IncDecOperatorKind Kind;
        public Operator Operator;

        public override int GetPrecedence()
        {
            return 30;
        }

        public override ITypeDef ComputeType(ITypeDef goal, bool needsRef, ErrorReport report)
        {
            // Some error?
            if (this.Operator == null)
                return null;
            ITypeDef type = this.Operator.ComputeType(null, true, report);
            // Some error?
            if (type == null)
                return null;
            if ( !(type is InstanceType ) )
            {
                report.Add( new ErrorEntry(this.Node) { Type = ErrorType.NotAnObject });
                return null;
            }
            if ( !type.CanBeAssignedTo(NumericType.Self) )
            {
                report.Add(new ErrorEntry(this.Node) { Type = ErrorType.ExpectedInt });
                return null;
            }

            return type;
        }
    }
}
